#include "admin.h"
#include "houqin.h"
#include "vip.h"
#include "account.h"
#include "logistics.h"
#include "shopper.h"
#include <stdlib.h>
#include <string.h>

void menu(void)
{
	system("clear");
	puts("*****超市管理系统*****");
	puts("1、管理员");
	puts("2、后勤");
	puts("3、顾客");
	puts("4、退出");
}

int main(int argc,const char* argv[])
{
	g_hou_qin_cnt = load_data(hou_qin,sizeof(hou_qin),"houqin.dat") / sizeof(Houqin);
	g_vip_cnt = load_data(vip,sizeof(vip),"vip.dat") / sizeof(Vip);
	g_records_cnt = load_data(records,sizeof(records),"records.dat") / sizeof(Records);
	g_goods_cnt = load_data(goods,sizeof(goods),"goods.dat") / sizeof(Goods);
	g_loss_goods_cnt = load_data(loss_goods,sizeof(loss_goods),"lossgoods.dat") / sizeof(Loss_Goods);
	if(0 == g_records_cnt)
	{
		strcpy(records[0].collection,BOSS_ACCOUNT_INIT);
		g_records_cnt++;
	}
	for(;;)
	{
		if(0 == g_hou_qin_cnt)
		{
			system("clear");
			printf("当前无任何后勤人员信息！\n是否退出系统！(y/n)\n");
			if(yes_or_no_notips())
			{
				return 0;
			}
			menu_admin();
			continue;
		}
		menu();
		switch(get_cmd('1','4'))
		{
		case '1': menu_admin(); break;
		case '2': menu_goods(); break;
		case '3': menu_shopper(); break;
		case '4': 
			save_data(hou_qin,sizeof(Houqin)*g_hou_qin_cnt,"houqin.dat");
			save_data(vip,sizeof(Vip)*g_vip_cnt,"vip.dat");
			save_data(records,sizeof(Records)*g_records_cnt,"records.dat");
			save_data(goods,sizeof(Goods)*g_goods_cnt,"goods.dat");
			save_data(loss_goods,sizeof(Loss_Goods)*g_loss_goods_cnt,"lossgoods.dat");
			return 0;
		}
	}
	return 0;
}
